package com.javasm.adminapi.module.supplier.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.adminapi.common.exception.ExceptionEnum;
import com.javasm.adminapi.common.exception.JavasmException;
import com.javasm.adminapi.module.product1.dao.GgGoodsDao;
import com.javasm.adminapi.module.product1.entity.GgGoods;
import com.javasm.adminapi.module.product1.service.GgGoodsService;
import com.javasm.adminapi.module.supplier.dao.GgSupplierDao;
import com.javasm.adminapi.module.supplier.entity.GgSupplier;
import com.javasm.adminapi.module.supplier.service.GgSupplierService;
import com.javasm.adminapi.module.supplier.vo.ListVo;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品管理-供应商(GgSupplier)表服务实现类
 *
 * @author makejava
 * @since 2025-10-14 20:37:46
 */
@Service("ggSupplierService")
public class GgSupplierServiceImpl extends ServiceImpl<GgSupplierDao, GgSupplier> implements GgSupplierService {

    @Override
    public PageInfo<GgSupplier> listSupplierByCondition(ListVo vo) {

        //开始分页
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());

        LambdaQueryWrapper<GgSupplier> queryWrapper = new LambdaQueryWrapper<>();
        String inputCondition = vo.getInputCondition();
        String queryCondition = vo.getQueryCondition();
        if (queryCondition==null){
            throw new JavasmException(ExceptionEnum.Condition_Null);
        }
        //避免空指针
        if (!StringUtils.isNullOrEmpty(inputCondition)){

            if (queryCondition.equals("suppliername")){
                queryWrapper.like(GgSupplier::getSupplierName,inputCondition);
            }if (queryCondition.equals("contacts")){
                queryWrapper.like(GgSupplier::getContacts,inputCondition);
            }if (queryCondition.equals("phone")){
                queryWrapper.like(GgSupplier::getContactPhone,inputCondition);
            }if (queryCondition.equals("address")){
                queryWrapper.like(GgSupplier::getContactAddress,inputCondition);
            }if (queryCondition.equals("account")){
                queryWrapper.like(GgSupplier::getAccountNo,inputCondition);
            }if (queryCondition.equals("bank")){
                queryWrapper.like(GgSupplier::getBankOfDeposit,inputCondition);
            }

        }
        queryWrapper.orderByDesc(GgSupplier::getId);
        List<GgSupplier> list = list(queryWrapper);
        PageInfo<GgSupplier> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }

    @Resource
    GgGoodsService ggGoodsService;
    @Override
    public List<GgGoods> getProductListBySupplierId(Integer supplierId) {
        List<GgGoods> list = ggGoodsService.getListBySupplierId(supplierId);
        return list;
    }
}

